package pers.li.dao;

import pers.li.model.GoodsDetail;
import pers.li.model.GoodsDetailType;
import pers.li.utils.DataProcess;

import java.util.List;

public class GoodsDetailDao {
    private final DataProcess dp = new DataProcess(true);

    /**
     * 通过商品id获取商品参数类型
     *
     * @param goodId 商品id
     * @return 商品参数类型
     */
    public List<GoodsDetailType> getGoodsDetailTypeByGoodId(Integer goodId) {
        String sql = "select distinct tg.type_id,type_name from t_goodsdetail tg\n" +
                "    join t_goodsdetailtype tgt on tg.type_id = tgt.type_id\n" +
                "    WHERE goods_id = ?";
        return dp.getObjectList(sql, GoodsDetailType.class, goodId);
    }

    /**
     * 通过商品id和商品参数类型id获取商品详情参数
     * @param goodId 商品id
     * @param detailTypeId 商品类型id
     * @return 商品详情参数
     */
    public List<GoodsDetail> getGoodsDetailByGoodIdAndDetailTypeId(Integer goodId, Integer detailTypeId) {
        String sql = "select content_id,content\n" +
                "from t_goodsdetail where goods_id = ? AND type_id = ?";
        return dp.getObjectList(sql, GoodsDetail.class, goodId, detailTypeId);
    }


    public String getContentName(Integer contentId){
        String sql = "select content from t_goodsdetail where content_id = ?";
        return dp.getObject(sql,String.class,contentId);
    }

}
